import 'package:aio/aio.dart';
import 'package:app/src/http/url.dart';

///用户信息类
class UserInfo extends RollerBean {
  String localImgPath = ""; //本地图片路径

  ///判断是否有图片信息
  bool hasUserImg() {
    if (StringUtils.isNotEmpty(localImgPath)) {
      return true;
    }
    if (StringUtils.isNotEmpty(PersonPicture)) {
      return true;
    }
    return false;
  }

  /**
   * 服务器字段
   */

  String PersonPicture = ""; //fixme 员工照片
  ///获取用户图片地址
  String? getPersonPictureUrl() {
    if (StringUtils.isEmpty(PersonPicture)) {
      return null;
    }
    if (PersonPicture!.contains("http")) {
      return PersonPicture;
    } else {
      return Url.getFileUrl(PersonPicture);
    }
  }

  String OutCode = ""; //Nc主键
  String PersonCode = ""; //fixme NC人员编号(员工工号)
  String PersonId = ""; //员工编号
  String PersonName = ""; //人员名称
  String HomeTel = ""; //家庭电话
  String OfficeTel = ""; //办公电话
  String MobileNum = ""; //fixme 手机号码
  String Email = ""; //电子邮件
  String ParentOrgCode = ""; //所属组织
  String Operation = ""; //操作类型
  String OperationDate = ""; //操作时间
  String DeptCode = ""; //部门编码
  String BirthDate = ""; //出生日期
  String Sex = ""; //性别
  String nationality = ""; //民族
  String Marriage = ""; //婚姻状况
  String IdNumber = ""; //身份证号
  String DeptId = ""; //所在部门
  String HomeTown = ""; //籍贯
  String EntryDate = ""; //入职日期
  String position = ""; //职务
  String WorkType = ""; //工种
  String Post = ""; //岗位
  String Technical = ""; //技术职称
  String Political = ""; //政治面貌
  String Address = ""; //联系地址
  String HomeAddress = ""; //家庭地址
  String Graduated = ""; //毕业院校
  String Specialty = ""; //所学专业
  String Degree = ""; //最高学历
  String AccountType = ""; //户口性质
  String PersonType = ""; //员工性质
  String PersonStatus = ""; //员工状态
  String LearningResume = ""; //学习简历
  String WorkingResume = ""; //工作简历
  String AddDate = ""; //添加时间
  String EditDate = ""; //修改时间
  String FactoryId = ""; //所属工厂
  String IcCardNum = ""; //fixme IC卡号(token)
  String CanOvertimeWork = ""; //是否可加班：0，不可以；1，可以
  String SupplierId = ""; //供应商主键

  ///fixme 以下新增两个字段；时间：2023.11.24
  String? PassWord = null; //密码
  ///isForceChangePassword  0 是不强制 1是强制。
  String? isForceChangePassword =
      null; //是否强制用户修改密码;ERP 站点配置，增加配置项：强制用户修改密码 （密码和账号不能一致）

  ///fixme 判断是否需要强制修改密码，配置和密码都判断
  bool isNeedChangePassWord() {
    // print("==========================isForceChangePassword:$isForceChangePassword\t$PersonCode\t$PassWord");
    if (isForceChangePassword == "1") {
      //return true;
      if (PersonCode == PassWord) {
        return true; //账号与密码不能一致
      }
    }
    return false;
    // var b = BoolUtils.isBoolWithStr(isForceChangePassword);
    // if (b && PersonCode == PassWord) {
    //   return true; //账号与密码不能一致
    // }
    // return false;
  }

  ///fixme 判断是否需要强制修改密码,只判断配置不判断密码
  bool isNeedChangePassWord2() {
    // print("==========================isForceChangePassword:$isForceChangePassword\t$PersonCode\t$PassWord");
    if (isForceChangePassword == "1") {
      return true;
    }
    return false;
  }

  @override
  fromJson(Map json) {
    // TODO: implement fromJson
    localImgPath = json["localImgPath"]?.toString() ?? "";
    PersonPicture = json["PersonPicture"]?.toString() ?? "";
    OutCode = json["OutCode"]?.toString() ?? "";
    PersonCode = json["PersonCode"]?.toString() ?? "";
    PersonName = json["PersonName"]?.toString() ?? "";
    HomeTel = json["HomeTel"]?.toString() ?? "";
    OfficeTel = json["OfficeTel"]?.toString() ?? "";
    MobileNum = json["MobileNum"]?.toString() ?? "";
    Email = json["Email"]?.toString() ?? "";
    ParentOrgCode = json["ParentOrgCode"]?.toString() ?? "";
    Operation = json["Operation"]?.toString() ?? "";
    OperationDate = json["OperationDate"]?.toString() ?? "";
    DeptCode = json["DeptCode"]?.toString() ?? "";
    PersonId = json["PersonId"]?.toString() ?? "";
    BirthDate = json["BirthDate"]?.toString() ?? "";
    Sex = json["Sex"] ?? "";
    nationality = json["nationality"]?.toString() ?? "";
    Marriage = json["Marriage"]?.toString() ?? "";
    IdNumber = json["IdNumber"]?.toString() ?? "";
    DeptId = json["DeptId"]?.toString() ?? "";
    HomeTown = json["HomeTown"]?.toString() ?? "";
    EntryDate = json["EntryDate"]?.toString() ?? "";
    position = json["position"]?.toString() ?? "";
    WorkType = json["WorkType"]?.toString() ?? "";
    Post = json["Post"]?.toString() ?? "";
    Technical = json["Technical"]?.toString() ?? "";
    Political = json["Political"]?.toString() ?? "";
    Address = json["Address"]?.toString() ?? "";
    HomeAddress = json["HomeAddress"]?.toString() ?? "";
    Graduated = json["Graduated"]?.toString() ?? "";
    Specialty = json["Specialty"]?.toString() ?? "";
    Degree = json["Degree"]?.toString() ?? "";
    AccountType = json["AccountType"]?.toString() ?? "";
    PersonType = json["PersonType"]?.toString() ?? "";
    PersonStatus = json["PersonStatus"]?.toString() ?? "";
    LearningResume = json["LearningResume"]?.toString() ?? "";
    WorkingResume = json["WorkingResume"]?.toString() ?? "";
    AddDate = json["AddDate"]?.toString() ?? "";
    EditDate = json["EditDate"]?.toString() ?? "";
    FactoryId = json["FactoryId"]?.toString() ?? "";
    IcCardNum = json["IcCardNum"]?.toString() ?? "";
    CanOvertimeWork = json["CanOvertimeWork"]?.toString() ?? "";
    SupplierId = json["SupplierId"]?.toString() ?? "";

    PassWord = json["PassWord"]?.toString() ?? "";
    isForceChangePassword = json["isForceChangePassword"]?.toString() ?? "";

    key = PersonId;
    value = PersonName;
  }

  @override
  instance() {
    // TODO: implement instance
    return UserInfo();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["localImgPath"] = localImgPath;
    map["PersonPicture"] = PersonPicture;
    map["OutCode"] = OutCode;
    map["PersonCode"] = PersonCode;
    map["PersonName"] = PersonName;
    map["HomeTel"] = HomeTel;
    map["OfficeTel"] = OfficeTel;
    map["MobileNum"] = MobileNum;
    map["Email"] = Email;
    map["ParentOrgCode"] = ParentOrgCode;
    map["Operation"] = Operation;
    map["OperationDate"] = OperationDate;
    map["DeptCode"] = DeptCode;
    map["PersonId"] = PersonId;
    map["BirthDate"] = BirthDate;
    map["Sex"] = Sex;
    map["nationality"] = nationality;
    map["Marriage"] = Marriage;
    map["IdNumber"] = IdNumber;
    map["DeptId"] = DeptId;
    map["HomeTown"] = HomeTown;
    map["EntryDate"] = EntryDate;
    map["position"] = position;
    map["WorkType"] = WorkType;
    map["Post"] = Post;
    map["Technical"] = Technical;
    map["Political"] = Political;
    map["Address"] = Address;
    map["HomeAddress"] = HomeAddress;
    map["Graduated"] = Graduated;
    map["Specialty"] = Specialty;
    map["Degree"] = Degree;
    map["AccountType"] = AccountType;
    map["PersonType"] = PersonType;
    map["PersonStatus"] = PersonStatus;
    map["LearningResume"] = LearningResume;
    map["WorkingResume"] = WorkingResume;
    map["AddDate"] = AddDate;
    map["EditDate"] = EditDate;
    map["FactoryId"] = FactoryId;
    map["IcCardNum"] = IcCardNum;
    map["CanOvertimeWork"] = CanOvertimeWork;
    map["SupplierId"] = SupplierId;

    map["PassWord"] = PassWord;
    map["isForceChangePassword"] = isForceChangePassword;
    return map;
  }
}

///用户登录信息类
class UserPassData extends BaseBean {
  String? UserName = null; //登录账号

  String? FactoryId = null; //所属工厂

  String? PassWord = null; //密码

  String? NewPassWord = null; //新密码

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    UserName = json["localImgPath"] ?? "";
    FactoryId = json["localImgPath"] ?? "";
    PassWord = json["localImgPath"] ?? "";
    NewPassWord = json["localImgPath"] ?? "";
  }

  @override
  instance() {
    // TODO: implement instance
    return UserPassData();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["UserName"] = UserName;
    map["FactoryId"] = FactoryId;
    map["PassWord"] = PassWord;
    map["NewPassWord"] = NewPassWord;
    return map;
  }
}

///退回至；审核退回
///[{compareValue: N4008, showText: 778}, {compareValue: N6041, showText: 彭治铭}]
class NodeShow extends RollerBean {
  String? compareValue = null; //退回人id
  String? showText = null; //退回人名称
  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    super.fromJson(json);
    compareValue = json["compareValue"]?.toString() ?? "";
    showText = json["showText"]?.toString() ?? "";
    key = compareValue;
    value = showText;
  }

  @override
  instance() {
    // TODO: implement instance
    return NodeShow();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    // var map = <String, dynamic>{};
    var map = super.toJson();
    map["compareValue"] = compareValue;
    map["showText"] = showText;
    return map;
  }
}

///部门
class Department extends RollerBean {
  String? DeptId = null; //部门ID
  String? DeptName = null; //部门名称

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    DeptId = json["DeptId"] ?? "";
    DeptName = json["DeptName"] ?? "";
    key = DeptId;
    value = DeptName;
  }

  @override
  instance() {
    // TODO: implement instance
    return Department();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["DeptId"] = DeptId;
    map["DeptName"] = DeptName;
    return map;
  }
}

///申请人
class UserApplicant extends RollerBean {
  String? DeptName = ""; //部门名称

  String? PersonId = ""; //人员id

  String? PersonCode = ""; //人员工号

  String? PersonName = ""; //人员名称

  @override
  fromJson(Map<String, dynamic> json) {
    // TODO: implement fromJson
    DeptName = json["DeptName"] ?? "";
    PersonId = json["PersonId"] ?? "";
    PersonCode = json["PersonCode"] ?? "";
    PersonName = json["PersonName"] ?? "";
    key = PersonCode;
    value = PersonName;
  }

  @override
  instance() {
    // TODO: implement instance
    return UserApplicant();
  }

  @override
  Map<String, dynamic> toJson() {
    // TODO: implement toJson
    var map = <String, dynamic>{};
    map["DeptName"] = DeptName;
    map["PersonId"] = PersonId;
    map["PersonCode"] = PersonCode;
    map["PersonName"] = PersonName;
    return map;
  }
}
